home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 20 / 5 / DISK2058.ZIP / UNFAST.EXE / FINDBIN.FI < prev    next >
Text File  |  1980-01-01  |  1KB  |  41 lines

  1. ;== Find string using binary sorting =======================================
  2.  
  3. ;FINDBIN ( string, segment, address, records, length, compare_length )
  4. ;0 = not found, else element (1-records).
  5.  
  6. #short
  7. var find_bin_put
  8.  
  9. function find_bin(bin_str,bin_seg,bin_adr,bin_rec,bin_len,bin_cmp)
  10.     {
  11.     find_bin_put=1
  12.     bin_low=0:bin_high=bin_rec
  13.     if bin_rec=0 then return 0
  14.  
  15.     while bin_low<=bin_high
  16.     {
  17.     bin_mid=(bin_high-bin_low)/2+bin_low
  18.     if bin_mid>=bin_rec then find_bin_put=bin_rec+1:return 0
  19.     ;Compare string at BIN_STR and BIN_SEG|BIN_ADR+BIN_MID*BIN_LEN.
  20.     bin_m=bin_adr+bin_mid*bin_len
  21.  
  22. ;    m=bin_str:repeat bin_cmp print chr peek m;:m++
  23. ;    print " ??? ";
  24. ;    m=bin_m:repeat bin_cmp print chr bin_seg[m];:m++
  25. ;    print
  26.  
  27.     bin_q=compareb bin_cmp at bin_str with bin_seg|bin_m
  28.     if bin_q then
  29.         {
  30.         bin_c=bin_seg[bin_m+bin_q-bin_str]b
  31.         if peekb bin_q>bin_c
  32.         then bin_low=bin_mid+1
  33.         else bin_high=bin_mid-1
  34.         }
  35.     else return bin_mid+1
  36.     }
  37.     if bin_low>bin_rec then find_bin_put=bin_low-1
  38.     else find_bin_put=bin_low+1
  39.     return 0
  40.     }
  41.